<?php



session_start();
if(isset($_SESSION['username'])){
//    echo $_SESSION['username'];
    header('Location:./session_test.php');
    echo '跳转失败，请刷新';
    exit;
}


?>

<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <title>data_interactive</title>
                            <!--JavaScript脚本-->
    <script>
        var ws=new WebSocket("ws://192.168.0.109:8882");        //建立连接
        function connect(uri){
            ws=new WebSocket(uri);
        }
        // connect("ws://192.168.0.109:8882");
        ws.onopen=function (evt) {
            func1("h2_1","连接成功");
        };

        ws.onclose=function (evt) {
            func1("h2_1","连接断开");
        };
        ws.onmessage=function (evt) {
            func1("div_1","接收到："+evt.data);
        };
        ws.onerror=function (evt) {
            func1("h2_1","未知错误！！");
        };


        function senddat(){
            ws.send("hello server!!!");
        }










        function func1(id,str) {
            var x=document.getElementById(id);
            x.innerHTML=str;
        }

        function show_time() {

            var time=new Date();
            var h=time.getHours();
            var m=time.getMinutes();
            var s=time.getSeconds();

            // document.write(h+':'+m+':'+s);
            func1('p_1',h+':'+m+':'+s);
            setTimeout('show_time()',1000);

        }

    </script>


                            <!--CSS样式-->
    <style>

        .img{
            width: 500px;
            height: 500px;
            background-image: url("./cpl.jpeg");

        }
        .d1{

            width: 500px;
            height: 200px;
            color: #00fa00;
            background: #bf0000;
        }
        .d2{
            width: 200px;
            height: 100px;
            background: #0000bf;
            color: #bfbf00;
            padding-left: 10px;
        }



    </style>
                            <!--CSS样式-->

</head>

<body onload="show_time()">

<p id="p_1" align="center" style="color: #bf0000" >hello</p>

    <?php



    ?>
    <form action="http://192.168.0.109/test/session_test.php" method="post">
        <h2 id="h2_1">未连接</h2>
        <button type="button" id="b_1" onclick="connect('ws://192.168.0.109:8885')">连接</button>
        <p class="f1">账号：<input type="text" name="username"><p>
        <p>密码：<input type="password" name="password"></p>
        爱好：
        <input type="checkbox" name="box[]" value="电影">电影
        <input type="checkbox" name="box[]" value="汽车">汽车
        <input type="checkbox" name="box[]" value="编程">编程
        <p><input type="submit" name="submit" value="提交"></p>

        <select name="location" id="1" style="height: 40px">
            <option value="请选择">请选择</option>
            <option value="温州">温州</option>
            <option value="宁波">宁波</option>
            <option value="杭州">杭州</option>

        </select>

    </form>


<?php





?> <div id="div_1" class="d1"><br/> hello world </div>



    <div id="div_2" class="d2" onmouseover="func1('div_2','进入')" onmouseout="func1('div_2','你好')">你好</div>


    <p>
        <button type="button" onclick="func1('div_1','点我')">点我1</button>
        <button type="button" onmouseover="func1('div_1','进入')" onmouseout="func1('div_1','退出')">点我2</button>
<!--        <p><input type="text" value="ws://192.168.0.109:8888"> </p>-->
        <button type="button" onclick="senddat()"> 发送消息</button>

    </p>


    <div class="img"></div>

</body>
</html>
